package org.zjt.algorithm;

/**
 * 46进制的加法
 */
public class BinarySystem36 {


    public static void main(String[] args) {
        String val = "23DA9";
        String val2 = "10AE";
        String sumStr ="";

        int length =  Math.max(val.length(),val2.length());
        int bit = 16;
        boolean jinwei =false;
        for(int i = 0;i < length;i ++){
            int num1= getCharNum(val,i);
            int num2 = getCharNum(val2,i);
            int sum = num1 + num2;
            if(jinwei){
                sum += 1;
            }
            jinwei= false;
            if(sum >= bit){
                jinwei = true;
                sum = sum %bit;
            }
            if (sum < 10){
                sumStr = sumStr + sum;
            }else{
                char ch = 'A';
                ch= (char)(ch + sum - 10);
                sumStr = sumStr + ch;
            }
        }

        for(int i = sumStr.length() - 1;i > -1;i --){
            System.out.print(sumStr.charAt(i));
        }
    }

    public static int getCharNum(String val,int i) {
        int index1 = val.length() - 1 - i;
        if(index1 > -1){
            char ch = val.charAt(index1);
            int  intNum = ch - 48;
            if(intNum > 16){
                intNum = intNum - 7;
            }
           return  intNum;
        }
        return 0;
    }
}
